import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  }
]

export const asyncRoutes = [
  {
    path: '/system',
    component: Layout,
    name: '系统管理',
    meta: { title: '系统管理', icon: 'system' },
    children: [
      {
        path: 'user',
        name: '用户管理',
        component: () => import('@/views/system/user/index'),
        meta: { title: '用户管理', icon: 'user' }
      },
      {
        path: 'role',
        name: '角色管理',
        component: () => import('@/views/system/role/index'),
        meta: { title: '角色管理', icon: 'peoples' }
      },
      {
        path: 'menu',
        name: '菜单管理',
        component: () => import('@/views/system/menu/index'),
        meta: { title: '菜单管理', icon: 'tree-table' }
      }
    ]
  },
  {
    path: '/travel',
    component: Layout,
    name: '旅游管理',
    meta: { title: '旅游管理', icon: 'guide' },
    children: [
      {
        path: 'scenic',
        name: '景点管理',
        component: () => import('@/views/travel/scenic/index'),
        meta: { title: '景点管理', icon: 'scenic' }
      },
      {
        path: 'hotel',
        name: '酒店管理',
        component: () => import('@/views/travel/hotel/index'),
        meta: { title: '酒店管理', icon: 'hotel' }
      },
      {
        path: 'restaurant',
        name: '餐饮管理',
        component: () => import('@/views/travel/restaurant/index'),
        meta: { title: '餐饮管理', icon: 'food' }
      },
      {
        path: 'route',
        name: '路线管理',
        component: () => import('@/views/travel/route/index'),
        meta: { title: '路线管理', icon: 'route' }
      }
    ]
  }
]

const createRouter = () => new Router({
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...asyncRoutes]
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router 